import http from '@/utils/http'

import type { ApiResponse } from '@/types/api'

// 健康助手聊天接口类型
export interface HealthAssistantMessage {
  role: 'user' | 'assistant'
  content: string
  thinking?: boolean
}

// 健康助手聊天历史
export interface HealthAssistantChatHistory {
  messages: HealthAssistantMessage[]
}

// 健康助手请求接口
export interface Request {
  userPrompt: string;
  [property: string]: any;
}

/**
 * 发送消息到健康助手
 * @param userMessage 用户消息
 * @param id 聊天ID，用于维持会话上下文
 * @returns
 */
export const sendMessageToHealthAssistant = (userPrompt: string): Promise<ApiResponse<HealthAssistantMessage>> => {
  const formData = new FormData();
  formData.append('Query', userPrompt);

  const response = await http({
    url: '/user/evaluate/diaLogue',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
  return response.data;
}

/**
 * 获取健康助手聊天历史
 * @returns 聊天历史记录
 */
export const getHealthAssistantHistory = (): Promise<ApiResponse<HealthAssistantChatHistory>> => {
  return http({
    url: '/user/evaluate',
    method: 'GET',
  })
}
